NProgress.start();
window.onload = function () {
    NProgress.done();
};
$(function () {

    $.ajax({
        url: '/sys/indexv3Json',
        success: function (data) {
            //data=JSON.parse(data);
            var firstdaryHtml = '';
            var secondaryHtml = '';
            var secondaryHideHtml = '';
            var thirdaryHtml = '';
            var thirdaryHideHtml = '';
            $.each(data, function (index, value) {

                $.each(value.list, function (index2, value2) {

                    $.each(value2.list, function (index3, value3) {
                        //thirdaryHtml += '<li><a href="' + value3.page + '" target="mainFrame" class=" "><span class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font">&nbsp;</span></a></li>';
                        //thirdaryHideHtml += '<li><a class="_menu-link" href="' + value3.page + '" target="mainFrame"> <span data="95" class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font"></span></a></li>';
                        thirdaryHtml += '<li><input class="hidden" value="' + value3.page + '"/><a  target="mainFrame" class="openPage"><span class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font">&nbsp;</span></a></li>';
                        thirdaryHideHtml += '<li><input class="hidden" value="' + value3.page + '"/><a class="_menu-link openPage" target="mainFrame"> <span data="95" class="l menu-label">' + value3.thirdDary + '</span><span class="normal icon-font"></span></a></li>';

                    });

                    thirdaryHtml = '<ul class="open expandable-level1 expandable-content">' + thirdaryHtml + '</ul>';//三级菜单
                    thirdaryHideHtml = '<ul class="item-content hm-scroll hidden"><li class="nav-title">' + value2.secondDary + '</li>' + thirdaryHideHtml + '</ul>';
                    var color = '#fffff';
                    var yu=parseInt(index2 % 5);
                    switch (yu) {
                        case 5:
                            color = '#009ee1';
                            break;
                        case 4:
                            color = '#3ebc7d';
                            break;
                        case 3:
                            color = '#f8aa14';
                            break;
                        case 2:
                            color = '#ff7595';
                            break;
                        case 1:
                            color = '#588afc';
                            break;
                        case 0:
                            color = '#009ee1';
                            break;

                    }
                    secondaryHtml += '<li class="flow-analysis menu-item selected clearfix" ><a href="javascript:void(0)" class="expandable recordable open"><span class="fa ' + value2.icon + ' img_24" style="vertical-align: middle;font-size: 22px;margin-left:20px;margin-right: 8px;color: ' + color + ';"></span><span class="item-title">' + value2.secondDary + '</span></a>' + thirdaryHtml + '</li>';

                    secondaryHideHtml += '<li class="flow-analysis menu-item clearfix hover-menu"><span class="fa ' + value2.icon + ' img_32" style="vertical-align: middle;font-size: 24px;color:' + color + ';"></span000>' + thirdaryHideHtml + '</li>';
                    thirdaryHtml = '';

                    thirdaryHideHtml = '';


                });
                if (index != 0) {
                    firstdaryHtml += '<a data-toggle="menubar" href="#verticaltab' + index + '"' + ' role="button">' + value.firstdary + '</a>';
                    secondaryHtml = '<ul class="nav hm-scroll hidden" id="verticaltab' + index + '">' + secondaryHtml + '</ul>';
                } else {
                    firstdaryHtml += '<a class="selected"  href="#verticaltab' + index + '"' + ' role="button">' + value.firstdary + '</a>';

                    secondaryHtml = '<ul class="nav hm-scroll" id="verticaltab' + index + '">' + secondaryHtml + '</ul>';
                }
                secondaryHideHtml = '<ul class="simple-nav" id="verticaltab' + index + 'simple" >' + secondaryHideHtml + '</ul>';
                $("#slid_nav").append(secondaryHtml);
                $(".simple-nav-wrapper").append(secondaryHideHtml);
                secondaryHtml = '';
                secondaryHideHtml = '';
            });

            $(".view-tab").append(firstdaryHtml);
        }
    });


});
$().ready(function () {
    $(document).on('click', '.view-tab a:not(".default-a")', function () {
        var $menu = $(".nav-wrapper .nav");
        var $simplemenu = $(".simple-nav-wrapper .simple-nav");

        var $this = $(this);
        $(".view-tab a").removeClass("selected");
        $this.addClass("selected");

        //menu
        var $currentMenu = $($this.attr("href"));
        $menu.addClass('hidden');
        $currentMenu.removeClass('hidden');

        //simpleMenu
        var $currentSimpleMenu = $($this.attr("href") + "simple");
        $simplemenu.addClass('hidden');
        $currentSimpleMenu.removeClass('hidden');
        return false;
    });
    $(document).on('click', '.nav-wrapper .nav a', function () {
        var $this = $(this);
        var $menuItem = $(".nav-wrapper .nav a");
        $menuItem.removeClass("selected");
        $this.addClass("selected");
    });


    var resizeContentH = function (contentID, leftId) {
        jQuery(contentID).height(jQuery(window).height() - 50);
        $("#" + leftId).height(jQuery(document).height() - 70);
    };

    /*窗口尺寸重载*/
    resizeContentH("#mainFrame", "aside");
    $(window).resize(function () {
        resizeContentH("#mainFrame", "aside");
    });


    $("#cuttle").on('click', function (event) {
        if ($("#aside").outerWidth() > 65) {
            /*       $("#cuttle").attr('src', '../global/img/cuttle.png');*/
            $("#cuttle").removeClass('icon-cuttle').addClass('icon-spread');
            $("#aside").animate({width: '64px'});
            $("#logo").animate({width: '56px', paddingLeft: '8px'})
            ;
            $(".right_nav").addClass('open').removeClass('close');

            setTimeout(function () {
                $(".nav-wrapper").addClass('hidden');
                $(".simple-nav-wrapper").removeClass('hidden');
                $("#companyName").addClass('hidden');
            }, 200)
        } else {
            // $("#cuttle").attr('src', '../global/img/back.png');
            $("#cuttle").removeClass('icon-spread').addClass('icon-cuttle');

            $('#aside').animate({width: '180px'});
            $('#logo').animate({width: '160px', paddingLeft: '20px',});
            $(".right_nav").removeClass('open').addClass('close');
            setTimeout(function () {
                $(".nav-wrapper").removeClass('hidden');
                $(".simple-nav-wrapper").addClass('hidden');
                $("#companyName").removeClass('hidden');
            }, 200);

        }
        event.stopPropagation();
    });


    //三级菜单闭合或者展开
    $(document).on('click', ".expandable", function () {
        $this = $(this);
        var uClass = $this.next().attr("class");
        if (uClass.indexOf("open") == 0) {
            $this.next().css('display', 'none');
            $this.next().attr("class", "close expandable-level1 expandable-content");
        } else {
            $this.next().css('display', 'block');
            $this.next().attr("class", "open expandable-level1 expandable-content");
        }
    });


    //鼠标移上去和移下来事件
    $(document).on("mouseover", '.hover-menu', function () {
        $this = $(this);
        $this.find(".item-content").attr("class", "item-content hm-scroll");
        $this.find(".item-content").parent('li').addClass("a");
    });
    $(document).on("mouseout", ".hover-menu", function () {
        $this = $(this);
        $this.find(".item-content").attr("class", "item-content hm-scroll hide");
        $this.find(".item-content").parent('li').removeClass("a");
    });

    $(function () {
        $(".top-nav ul li:has(ul)").hover(function () {
            $(this).children("ul").stop(true, true).slideDown(400);
        }, function () {
            $(this).children("ul").stop(true, true).slideUp("fast");
        });
    })
});

/*打开新页面*/
$(document).on('click', '.openPage', function (e) {
    var newPage = $(this).prev().val();
    $("#mainFrame").attr('src', newPage);
    e.stopPropagation();
});

function _send(type, sel, val) {
    //alert(v);
    if (type == "append") {
        $("#mainFrame").contents().find('#' + sel).append(val);
    } else if (type == "val") {
        $("#mainFrame").contents().find('#' + sel).val(val);
    } else if (type == "html") {
        $("#mainFrame").contents().find('#' + sel).html(val);
    } else if (type == "method") {//调用子页面的receive方法
        $("#mainFrame")[0].contentWindow.receive(val);
    }

}

function _get(sel, val) {
    if (val)
        return $("#mainFrame").contents().find('#' + sel).find(val);
    else
        return $("#mainFrame").contents().find('#' + sel).val();
}

$(function (e) {
    $("#fullScreen").on('click', function () {
        $("#content").fullScreen();
        // window.event.stopPropagation();
    })
});


